import geemap
# clip image to a region

# function
def clip_region(image):
    """
    clip_region(image)
        para: image, the iamge to be clipped
        roi_box: geometry, the target region
    """
    image = image.clip(roi_box)
    return image

## calculation of image
# -----------------------------------------------------------------------------

# get the statistics of image bands
geemap.image_stats(image, scale = 1000)


# reproject
# -----------------------------------------------------------------------------
# see this page for resolution and projection: 
# https://spatialthoughts.com/2021/05/13/aggregating-population-data-gee/

# get the native resolution
image.projection().nominalScale()


# reduce resolution
def resample_1km(image):
    """
    resample image to 1000m resolution using Nearest method
    """
    image = image.reproject(crs = "EPSG:4326", scale = 1000)
    return image


# reduce resolution
def resample_1km(image):
    """
    resample image to 1000m resolution using bilinear method
    """
    image = image.resample('bilinear').reproject(crs = "EPSG:4326", scale = 1000)
    return image